package br.com.array.android.ma.view.activity;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import br.com.array.android.ma.R;
import br.com.array.android.ma.model.Notificacao;
import br.com.array.android.ma.service.ServiceNotificacaoListener;
import br.com.array.android.ma.view.adapter.NotificacaoAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by leonardo.neves on 06/08/2014.
 */
public class TelaPrincipalActivity extends ListActivity implements ServiceNotificacaoListener{

    private NotificacaoAdapter adapter;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tela_principal_activity);

        List<Notificacao> notificacoes = new ArrayList<Notificacao>();
        for (int i = 0; i < 3; i++){
            notificacoes.add(new Notificacao("Fator de demanda", "Descrição do alarme recebido", "07/08", 0));
            notificacoes.add(new Notificacao("Energia reativa", "Descrição do alarme recebido", "07/08", 0));
            notificacoes.add(new Notificacao("Fator de potência", "Descrição do alarme recebido", "07/08", 0));
        }
        adapter = new NotificacaoAdapter(this, R.layout.adapter_notificacao, notificacoes);
        getListView().setAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Intent intent = new Intent(TelaPrincipalActivity.this, DetalheNotificacaoActivity.class);
        Notificacao notificacao = adapter.getItem(position);
        intent.putExtra(DetalheNotificacaoActivity.KEY_MODEL, notificacao);
        startActivity(intent);
    }

    @Override
    public void onSucesso(List<Notificacao> notificacaos) {

    }

    @Override
    public void onErro(Exception e) {

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_principal, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.menuPrincipal:
                Intent intent = new Intent(TelaPrincipalActivity.this, ConfiguracaoPreferenceActivity.class);
                startActivity(intent);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}